package com.mock.engineerprocess.domain.impl;

import com.mock.engineerprocess.domain.MockUserStorage;
import com.mock.engineerprocess.domain.proxy.MockUserStorageProxy;
import edu.fudan.langlab.domain.security.User;
import edu.fudan.langlab.domain.security.impl.UserImpl;
import edu.fudan.mylang.pf.BaseModelObject;
import edu.fudan.mylang.pf.IObjectFactory;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.hibernate.annotations.DiscriminatorOptions;

@Entity
@DiscriminatorValue("MOCKUSERSTORAGE_TYPE")
@DiscriminatorOptions(force = true)
@DiscriminatorColumn(length = 64)
@Table(name = "mockuserstorage")
public class MockUserStorageImpl extends BaseModelObject implements MockUserStorage {
  public MockUserStorageImpl() {
    super();
  }
  
  public MockUserStorageImpl(final User user) {
    super();
    this.user = user;
  }
  
  @JoinColumn(name = "user_id")
  @ManyToOne(targetEntity = UserImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private User user;
  
  public User getUser() {
    return this.user;
  }
  
  public MockUserStorage setUser(final User user) {
    this.user = user;
    return this;			
    
  }
  
  public static MockUserStorage create(final User user, final IObjectFactory objectFactory) {
    com.mock.engineerprocess.domain.MockUserStorage mockUserStorage = new com.mock.engineerprocess.domain.impl.MockUserStorageImpl(
    	user
    );
    objectFactory.create(mockUserStorage);
    return mockUserStorage;			
    
  }
  
  public static MockUserStorage createMockUserStorageImpl(final User user, final IObjectFactory objectFactory, final Procedure1<MockUserStorage> init) {
    com.mock.engineerprocess.domain.MockUserStorage mockUserStorage = new com.mock.engineerprocess.domain.impl.MockUserStorageImpl(
    	user
    );
    objectFactory.create(mockUserStorage);
    init.apply(mockUserStorage);
    
    return mockUserStorage;			
    
  }
  
  public MockUserStorageProxy toProxy() {
    com.mock.engineerprocess.domain.proxy.MockUserStorageProxy proxy = new com.mock.engineerprocess.domain.proxy.MockUserStorageProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
